package com.jason;

import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;

import javax.print.attribute.standard.Media;

import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.autoconfigure.jsonb.JsonbAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter4;
import com.jason.interceptors.LoginInterceptor;
@Configuration
public class WebConfig extends WebMvcConfigurationSupport {

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		InterceptorRegistration interceptor = registry.addInterceptor(new LoginInterceptor());
		interceptor.addPathPatterns("/**");
		interceptor.excludePathPatterns("/user/login/**","/login**","/css/**","/fonts/**","/img/**","/js/**","/user/test/**");
		super.addInterceptors(registry);
	}

	@Override
	protected void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
		// TODO Auto-generated method stub
		super.configureMessageConverters(converters);
		FastJsonHttpMessageConverter4 converter=new FastJsonHttpMessageConverter4();
		FastJsonConfig config=new FastJsonConfig();
		config.setCharset(Charset.forName("UTF-8"));
		config.setSerializerFeatures(SerializerFeature.PrettyFormat);
		converter.setFastJsonConfig(config);
		List<MediaType> list=new ArrayList<>();
		list.add(MediaType.ALL);
		converter.setSupportedMediaTypes(list);
		converters.add(converter);
	}

	@Override
	protected void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("/**","/").addResourceLocations("classpath:/static/");
		super.addResourceHandlers(registry);
	}
	
}
